import http from '@ohos.net.http';

const TAG = 'tiktok'

export async function get100kFile() {
  let num: number = 0
  for (let index = 0; index < 100000; index++) {
    num = index - 1;
  }
  let httpRequest = http.createHttp();
  httpRequest.request(
    "https://www.baidu.com/",
    {
      method: http.RequestMethod.GET, // 可选，默认为http.RequestMethod.GET
      connectTimeout: 5000, // 可选，默认为60s
      readTimeout: 5000, // 可选，默认为60s
    }, (err, data) => {
    if (!err) {
      console.log(TAG,"get successfully")
      return 0 // 8+
    } else {
      httpRequest.destroy();
      return 0
    }
    return 0
  }
  );
  return 0
}
export async function post100kFile() {
  let httpRequest = http.createHttp();
  httpRequest.request(
    "https://www.baidu.com/",
    {
      method: http.RequestMethod.POST, // 可选，默认为http.RequestMethod.GET
      // 开发者根据自身业务需要添加header字段
      header: {
        'Content-Type': 'application/json'
      },
      // 当使用POST请求时此字段用于传递内容
      extraData: {
        "data": "data to send",
      },
      connectTimeout: 60000, // 可选，默认为60s
      readTimeout: 60000, // 可选，默认为60s

    }, (err, data) => {
    if (!err) {
      console.log(TAG,"post successfully")
      return "0"
    } else {
      httpRequest.destroy();
      return "0"
    }
  });
  return "0"

}
